<?php
class WorkflowsController extends AppController {

    var $name = 'Workflows';
    var $helpers = array('Ajax', 'Javascript', 'Paginator', 'Text');
    var $components = array('RequestHandler');

    function admin_index() {
        $this->Workflow->recursive = 0;
        $this->set('workflows', $this->paginate());
    }

    function admin_view($id = null) {
        if (!$id) {
            $message = sprintf(__('I18N_INVALID_ENTITY'),__('I18N_WORKFLOW'));
            $this->showMessage($message);
        }
        $this->set('workflow', $this->Workflow->read(null, $id));
    }

    function admin_add() {
        if (!empty($this->data)) {
            $this->Workflow->create();
            if ($this->Workflow->save($this->data)) {
                $message = 'I18N_SUCCESSFULY_ADDED';
            } else {
                $message = 'I18N_ERROR_NOT_ADDED';
            }
            $this->showMessage($message);
        }
    }

    function admin_edit($id = null) {
        if (!$id && empty($this->data)) {
            $message = sprintf(__('I18N_INVALID_ENTITY'),__('I18N_WORKFLOW'));
            $this->showMessage($message);
        }
        if (!empty($this->data)) {
            if ($this->Workflow->save($this->data)) {
                $message = 'I18N_SUCCESSFULY_UPDATED';
            } else {
                $message = 'I18N_ERROR_NOT_UPDATED';
            }
            $this->showMessage($message);
        }
        if (empty($this->data)) {
            $this->data = $this->Workflow->read(null, $id);
        }
    }

    function admin_delete($id = null) {
        if (!$id) {
            $message = sprintf(__('I18N_INVALID_ENTITY'),__('I18N_WORKFLOW'));
            $this->showMessage($message);
        }
        if ($this->Workflow->delete($id)) {
            $message = 'I18N_SUCCESSFULY_REMOVED';
        }
        else {
            $message = 'I18N_ERROR_NOT_REMOVED';
        }
        $this->showMessage($message);
    }
}
?>